package com.operate.api.app.dramas.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.operate.api.app.dramas.domain.vo.*;
import com.operate.api.base.ApiIndex;
import com.operate.api.base.IDEntity;
import com.operate.api.base.R;
import com.operate.api.base.RestPage;
import com.operate.api.operate.dramas.service.IDramasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api( tags = ApiIndex.AppVideoController)
@RequestMapping(value = "/api/app/video")
@RestController
public class AppVideoController {

    @Autowired
    private IDramasService service;


    @ApiOperation(value = "查询视频列表【播放页面】")
    @GetMapping(value = "/list")
    public R<List<AppVideoVO>> video_list(
            @ApiParam(value = "查询参数") @ModelAttribute AppVideoSearchVO searchVO) {
        List<AppVideoVO> list = service.getAppVideoList(searchVO);
        return new R(list);
    }

    @ApiOperation(value = "查询随机视频列表【播放页面】")
    @GetMapping(value = "/random_list")
    public R<List<AppVideoVO>> randomVideoList(
            @ApiParam(value = "查询参数") @ModelAttribute AppRandomVideoSearchVO searchVO) {
        List<AppVideoVO> one = service.getRandomVideoList(searchVO);
        return new R(one);
    }

    @ApiOperation(value = "查询视频数据")
    @GetMapping(value = "/one")
    public R<AppVideoVO> video_one(
            @ApiParam(value = "查询参数") @ModelAttribute IDEntity idEntity) {
        AppVideoVO list = service.getAppVideoOne(idEntity.getId());
        return new R(list);
    }


    @ApiOperation(value = "查询我观看视频列表【观看历史】")
    @GetMapping(value = "/play_list")
    public R<List<AppVideoPlayLogVO>> play_list(
            @ApiParam(value = "查询参数") @ModelAttribute AppVideoPlayLogSearchVO searchVO) {
        List<AppVideoPlayLogVO> list = service.getAppPlayList(searchVO);
        return new R(list);
    }

    @ApiOperation(value = "查询我观看剧集列表【观看历史】")
    @GetMapping(value = "/play_drama_list")
    public R<List<AppVideoPlayLogVO>> play_drama_list(
            @ApiParam(value = "查询参数") @ModelAttribute AppVideoPlayLogSearchVO searchVO) {
        List<AppVideoPlayLogVO> list = service.getAppPlayDramaList(searchVO);
        return new R(list);
    }


    @ApiOperation(value = "查询我喜欢视频列表【喜欢列表】")
    @GetMapping(value = "/like_list")
    public R<RestPage<List<AppVideoPlayLogVO>>> like_list(
            @ApiParam(value = "查询参数") @ModelAttribute AppVideoPlayLogSearchVO searchVO) {
        List<AppVideoPlayLogVO> list = service.getAppLikeList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }


    @ApiOperation(value = "得到我喜欢数量[需要登录]")
    @GetMapping(value = "/like_num")
    @SaCheckLogin
    public R<Integer> like_num() {
        return new R(service.getLikeNum());
    }

    @ApiOperation(value = "得到我观看数量[需要登录]")
    @GetMapping(value = "/play_num")
    @SaCheckLogin
    public R<Integer> play_num() {
        return new R(service.getPlayNum());
    }



    @ApiOperation(value = "清空观看历史[需要登录]")
    @PostMapping(value = "/cancel_plays")
    @SaCheckLogin
    public R cancel_plays() {
        service.cancelPlays();
        return new R();
    }

    @ApiOperation(value = "视频点赞")
    @PostMapping(value = "/like_video")
    public R like_video(@ApiParam(value = "参数")  @RequestBody AppVideoLikeVO vo) {
        service.likeVideo(vo);
        return new R();
    }

    @ApiOperation(value = "检查是否被用户点赞[需要登录]")
    @PostMapping(value = "/check_like")
    @SaCheckLogin
    public R<Boolean> check_like(@ApiParam(value = "参数")  @RequestBody AppVideoLikeVO vo) {
        Boolean r=service.checkLikeVideo(vo);
        return new R();
    }


    @ApiOperation(value = "视频取消点赞[需要登录]")
    @PostMapping(value = "/cancel_collect")
    @SaCheckLogin
    public R cancel_like(@ApiParam(value = "参数")  @RequestBody AppVideoLikeVO vo) {
        service.cancelLikeVideo(vo);
        return new R();
    }

    @ApiOperation(value = "视频播放")
    @PostMapping(value = "/play_video")
    public R play_video(@ApiParam(value = "参数")  @RequestBody AppVideoPlayVO vo) {
        service.playVideo(vo);
        return new R();
    }
    @ApiOperation(value = "视频解锁(购买)[需要登录]")
    @PostMapping(value = "/pay_video")
    @SaCheckLogin
    public R pay_video(@ApiParam(value = "参数")  @RequestBody AppVideoConsumeVO vo) {
        service.payVideo(vo);
        return new R();
    }




}